using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Deepcode.Flux.Core.Systems.Workflow;
using Deepcode.Flux.Core.Systems.Workflow.Interfaces;
using Deepcode.Flux.Core.Systems.Workflow.Info;
using Deepcode.Flux.Core.Services.XML;
using Deepcode.Flux.Core.Services.Assistant;

public partial class Private_Config_Workflow_SendEmailConfig : System.Web.UI.UserControl, Deepcode.Flux.Core.Systems.Workflow.Interfaces.IWorkflowConfigControl
{
	public void SetWorkflow( string HandlerID, int DefinitionID, int ProcessID )
	{
		// Get data for the various selections etc
		WorkflowEngine Engine = new WorkflowEngine(HandlerID);
		if (Engine == null) return;
		
		// GetWorkflowTaskableOperators
		this.CSV_GroupID.Items.Clear();
		foreach (WorkflowTaskableOperator wto in Engine.GetTaskableOperators())
			this.CSV_OperatorID.Items.Add(new ListItem(wto.OperatorName, wto.OperatorID.ToString()));

		// GetWorkflowTaskableOperatorGroups();
		this.CSV_GroupID.Items.Clear();
		foreach (WorkflowTaskableGroup wtg in Engine.GetTaskableGroups())
			this.CSV_GroupID.Items.Add(new ListItem(wtg.GroupName, wtg.GroupID.ToString()));

		// GetWorkflowTaskableSpecialMethods();
		this.GetUserMethod.Items.Clear();
		foreach (WorkflowTaskableMethodInfo info in Engine.GetWorkflowTaskableMethods())
			this.GetUserMethod.Items.Add(new ListItem(info.FriendlyName, info.MethodName));
	}

	/// <summary>
	/// Load the XML into the controls
	/// </summary>
	/// <param name="XmlDatapacket"></param>
	public void DeSerialise(string XmlDatapacket)
	{
		PropertyBag pb = new PropertyBag( XmlDatapacket );
		ControlUtil.SetSelectedCSV( CSV_OperatorID.Items, pb.Get("ToOperators", "") );
		ControlUtil.SetSelectedCSV( CSV_GroupID.Items, pb.Get("ToGroups", "") );
		ControlUtil.SetSelectedCSV( GetUserMethod.Items, pb.Get("ToMethods", "") );
		ToEmails.Text = pb.Get("ToEmails", "");
		Subject.Text = pb.Get("Subject", "");
		Body.Text = pb.Get("Body", "");
	}
	/// <summary>
	/// Load the control values into XML
	/// </summary>
	/// <returns></returns>
	public string Serialise()
	{
		string SelOps = ControlUtil.GetListSelectedCSV( CSV_OperatorID.Items );
		string SelGroups = ControlUtil.GetListSelectedCSV( CSV_GroupID.Items );
		string SelMethods = ControlUtil.GetListSelectedCSV( GetUserMethod.Items );

		PropertyBag pb = new PropertyBag();
		pb.Add("ToOperators", SelOps);
		pb.Add("ToGroups", SelGroups);
		pb.Add("ToMethods", SelMethods);
		pb.Add("ToEmails", ToEmails.Text );
		pb.Add("Subject", Subject.Text);
		pb.Add("Body", Body.Text);
		
		return pb.Serialise();
	}
}
